package tech.aistar.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tech.aistar.entity.UserRelation;

import java.util.List;

public interface UserRelationMapper {
    //根据用户id 查出 它的关注的用户集合
    @Select("select * from user_relation where id = #{value} and status = 0")
    List<UserRelation> findFansNum(Integer id);

    //根据用户id 查出 它的粉丝的用户集合
    @Select("select * from user_relation where user_byid= #{value} and status = 0")
    List<UserRelation> findFoucNum(Integer userByid);

//    删除关注的人
    @Update("update user_relation set status = 1 where id = #{id} and user_byid = #{user_byid}")
    void delFouc(@Param("id") Integer id, @Param("user_byid") Integer userId);

    //添加两者关系
    @Insert("insert into user_relation values (#{reId},#{id},now(),#{userByid},#{status})")
    void addShip(UserRelation userRelation);

    //检查俩者之前是否存在关系
    @Select("select re_id from user_relation where id=#{id} and user_byid = #{user_byid} and status = #{status}")
    Long findShip(@Param("id") Integer id, @Param("user_byid") Integer user_byid, @Param("status") Integer status);

    //改变(增加)两者关系
    @Update("update user_relation set status = 0 where id = #{id} and user_byid = #{user_byid}")
    void chanageShip(@Param("id") Integer id, @Param("user_byid") Integer userId);

    //检测是否为互相关注
    @Select("select re_id from user_relation where id=#{id} and user_byid = #{user_byid} and status = 0")
    Long bothShip(@Param("id") Integer id, @Param("user_byid") Integer user_byid);


}
